<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

<meta charset="utf-8">

<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">

<meta content="yes" name="apple-mobile-web-app-capable">

<meta content="black" name="apple-mobile-web-app-status-bar-style">

<meta content="telephone=no" name="format-detection">

<title>设置密码</title>

<link href="style/login.css" rel="stylesheet" type="text/css" />

<link href="css/vant.css" rel="stylesheet" type="text/css" />

<script src="js/jquery-3.3.1.min.js"></script>

<script src="js/vue.js"></script>

<script src="js/axios.js"></script>

<script src="js/qs.js"></script>

<script src="js/MD5.js"></script>

<script src="js/vant.js"></script>

</head>



<body>

<div id="app">

    <div class="ve_title">{{titles}}</div>

    <div class="main">

        <div class="login_txt">设置密码</div>

        <input id="send" type="hidden" value="60" />

        <div class="login_o" id="phone_login">

            <div class="login_text">手机号</div>

            <div class="login_input">

                <input v-model="from.phone" id="phone" type="text" class="phone_input" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="11" onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码"/>

            </div>

            <div class="login_text" style="margin-top:10px">短信验证码</div>

            <div class="login_input_code">

                <input v-model="from.sms_code" id="code" type="text" class="code_input" style="width: 50%;" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="6" onafterpaste="this.value=this.value.replace(/\D/g,'')"/>

                <div class="code_getcode" @click="get_sms_codeSet()">获取验证码</div>

            </div>

            <div class="login_text" style="margin-top:10px">密码</div>

            <div class="login_input_code">

                <input v-model="from.password" id="upassword" type="password" class="code_input" placeholder="请输入密码"/>

            </div>

            <a href="login.html" class="login_text" style="margin-top:10px; font-size:13px; text-align:right;">返回登录</a>

        </div>

        <div class="login_but_o" @click="setpssword()">设置密码</div>

    </div>

</div>

</body>

<script>

var app = new Vue({

    el: '#app',

    data: {
        sendData: {},

        vid:'',

        titles:'',

        helloData: {},

        from:{

            sms_code: "",

            phone: "",

            password: "",

            vid:'',

        }

    },

    created(){

        this.setCanS()

    },

    methods: {

            //设置参数

            setCanS(){

                let Request = new Object()

                Request = GetRequest()

                this.vid = Request['vid']

                //获取场馆名称

                if(this.vid==undefined||this.vid==''){

                    this.vid=''

                }else{

                    sessionStorage.setItem('vid',this.vid)

                }

                this.from.vid=sessionStorage.getItem('vid',this.vid)

                const params={

                    vid:sessionStorage.getItem('vid')

                }

                sessionStorage.setItem('logo','1')

                axios.get('/mobileapi/login_staff.php?act=login',{params:params}).then(data => {

                    console.log(data.data)

                    let { msg, code} = data.data

                        if (code !== 200) {

                            window.vant.Toast.fail(msg)

                        } else {

                            var datas = data.data.data.Vname

                            this.titles=datas

                            console.log(this.titles)

                        }

                        

                    }).catch(function (error) { 

                        console.log(error); 

                });

            },

            //登录设置密码

            setpssword() {

                sessionStorage.setItem('logo','1')

                let password=md5(this.from.password)

                password=md5(password)

                console.log(password)

                let from = { 

                        phone: this.from.phone,

                        password: password,

                        sms_code:this.from.sms_code,

                        vid:this.vid

                    };
                    from["data"] = this.sendData;

                from =JSON.stringify(from)

                let sign=md5(from)

                let params={

                    from:from,

                    sign:sign

                }

                axios.post('/mobileapi/login_staff.php?act=edit_password',

                Qs.stringify(params)).then(function(response){

                    let { msg, code} = response.data

                        if (code !== 200) {

                            window.vant.Toast.fail(msg)

                        } else {

                            window.vant.Toast.success("设置密码成功")

                            setTimeout(function(){

                                window.location.href='login.html'

                                }, 2000);

                        }

                    }).catch(function (error) { 

                        console.log(error); 

                });

            },

             //验证手机号正不争取

             isPoneAvaila(phone) {

                var myreg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/

                if (!myreg.test(phone)) {

                    return false;

                } else {

                    return true;

                }

            },

            //获取手机验证码

            get_sms_codeSet(){

                var send=parseInt($("#send").val());

	            var phone=parseInt($("#phone").val());

                if(!this.isPoneAvaila(this.from.phone)){

                    window.vant.Toast.fail("请输入正确的手机号")

                    return false;

                }

                const params={

                    phone:this.from.phone

                }

                if(send==60){
                    var that = this;

                    axios.post('/mobileapi/member/login.php?act=getsms',Qs.stringify(params)).then(function(response){

                            if(response.data.code=="200"){
                                that.sendData = response.data.data;

								window.vant.Toast.success("短信已发，请注意查收")

							}else{

								window.vant.Toast.fail(response.data.msg)

							}

                        }).catch(function (error) {

                            console.log(error)

                            window.vant.Toast.fail("短信发送失败！请确认手机号是否正确。");

                    })   

                    var set=setInterval(function(){

                        var send_t=--send;

                        $(".code_getcode").html(""+send_t+"秒");

                        $("#send").val(--send_t)

                    }, 1000);

                    setTimeout(function(){

                        $(".code_getcode").html("重新获取");

                        $("#send").val(60)

                        clearInterval(set);

                    }, 60000);

                }	

            },

           

        }  

})

</script>

<script type="text/javascript" src="js/js.js"></script>

</html>